package com.zcsy.manage.owner.filter;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
 * 拦截器生成新的请求参数
 * @Description: 
 * @author: zt
 * @date: 2016年6月27日
 * @version： v1.0 Copyright (c) 2014 Wuhan Hongyi Infomation Co., Ltd.
 */
public class ParamsHttpServletRequestWrapper extends HttpServletRequestWrapper{
	
	/** 新的参数 */
	Map<String, Object> params;

	public ParamsHttpServletRequestWrapper(HttpServletRequest request) {
		super(request);
		params = new HashMap<>();
		params.putAll(request.getParameterMap());
	}

	@Override
	public Map getParameterMap() {
		return params;
	}
	
	@Override
	public String getParameter(String name) {
		Object obj = params.get(name);
		System.out.println(obj.getClass());
		if(obj instanceof String []){  
		    String [] param = (String [])obj;  
		    return param[0];
		} else if (obj instanceof String){
			return (String) params.get(name);
		}
		return null;
		
	}
	
	@Override
	public String[] getParameterValues(String name) {  
		 Object obj = params.get(name);
			System.out.println(obj.getClass());
			if(obj instanceof String []){  
			    String [] param = (String [])obj;  
			    return param;
			} else if (obj instanceof String){
				return new String[]{(String) params.get(name)};
			}
			return null;
    }  
	
}
